#include <gtest/gtest.h>

#include <QUuid>

#include <Type/UserInfo.h>
#include <Store/UserInfoTable.h>

#include <PredefinedConstance/UserInfo.h>
#include "CRUDTest.h"
#include "Database.h"

using namespace std;

namespace Store
{
	class UserInfo
	{
	public:
		UserInfo()
		{
			Database();
		}
        ~UserInfo()
        {
            try
            {
                remove();
            }
            catch (...)
            {
            }
        }
	public:
		typedef TCServer::Type::UserInfo DataType;
		typedef TCServer::Store::UserInfoTable TableType;
	public:
		typedef quint64 InsertResult;
		quint64 insert()
		{
            insertedVal = testVals.val2insert;
			auto id = TableType::insert(testVals.val2insert);
            testVals.val2update.id = insertedVal.id = id;
            return id;
		}

		typedef DataType QueryResult;
		QueryResult query()
		{
			return TableType::query(insertedVal.id);
		}

		typedef void UpdateResult;
		void update()
		{
            insertedVal = testVals.val2update;
			return TableType::update(insertedVal);
		}

		typedef void RemoveResult;
		void remove()
		{
            return TableType::remove(testVals.val2insert.id);
		}

	public:
		bool checkInsert(const QueryResult &result)
		{
            return insertedVal.id == result.id
                && insertedVal.headUrl == result.headUrl
                && insertedVal.nickname == result.nickname
                ;
		}
	private:
		PredefinedConstance::UserInfo testVals;
        DataType insertedVal;
	};
}

INSTANTIATE_TYPED_TEST_CASE_P(Store_UserInfo, CRUDTest, Store::UserInfo);
